Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
Why do local functions have the "internal" access modifier?

Why does the Roslyn compiler generate local functions with the internal access modifier (in IL, assembly) instead of private?

    private void M()
    {
        bool f = true;
        bool x1() => f;
        static bool x2() => true;
    }
    .method assembly hidebysig static
        bool '<M>g__x1|0_0' (
            valuetype C/'<>c__DisplayClass0_0'& ''
        ) cil managed { ... }

    .method assembly hidebysig static
        bool '<M>g__x2|0_1' () cil managed { ... }

sharplab.io

Docs say that it should be private: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/local-functions

Local functions are private methods of a type that are nested in another member.

Because all local functions are private, including an access modifier, such as the private keyword, generates compiler error CS0106

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Looks like code reuse artifact. Roslyn probably uses same code to handle local functions and lambdas, but injects method definitions in different classes.

In case of lambda it injects lambda body to generated closure (DisplayClass) class and it should be internal to be referenced from calling function.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!